﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class TJTVA09 
    {

        public TJTVA09()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return; 
            MV = new VVAFARBEN();
            DataContext = MV;  
            InitializeComponent();
            ART = "S" + MV.year.Substring(3, 1) + "-0";
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwVF = dwMaster;
            if (dwMaster != null)
            {
                FARBGRP = dwMaster["VAFFARBGRP"].ToString();
                PRART = dwMaster["VAAARTST"].ToString().PadRight(1) + TMV.VAFPART + TMV.VAFPVAR.PadRight(3) + TMV.VAFFFARBE + TMV.VAFBESCHICH + TMV.VAFDESS + TMV.VAFCOLORIT + TMV.VAFPGROE;
                KEY = dwMaster["VAFKOLL"].ToString() + dwMaster["VAFART"].ToString() + dwMaster["VAFFARBE"].ToString();
                //ART =  dwMaster["VAFART"].ToString().Trim();
                //FARBE = dwMaster["VAFFARBE"].ToString().Trim(); 
                if(IsShowTxt)
                {
                    TXTISIND = KEY.PadRight(60);
                }               
            }
            else
            {
                //ART = "";
                //FARBE = "";
                PRART = "";
                KEY = "";
                TXTISIND = "";
            }
        }

        public override void QueryCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            if (ART.Trim().Length < 3)
            {
                MessageBox.Show("条件太少,数据太多");
                return;
            }
            dwData = TBMain.NewRow();
            dwData["VAFMANDANT"] = app.Mandant;
            dwData["VAFKOLL"] =KOLL;
            dwData["VAFART"] = ART.Trim();
            dwData["VAFFARBE"] = FARBE.Trim();
            SResult = TMV.QVAF09(dwData);
            MergeData(SResult, false);
            base.QueryCommand(sender, e);
        }
        private void ART_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            try
            {
                if (e.Key != System.Windows.Input.Key.Enter)
                    return;
                this.Focus();
                QueryCommand(sender, null);
                txtART.Focus();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
        public override void OnCARTChg(string art)
        {

            if (art.Length < 21)
            {
                INFO = "";
                return;
            }
            ART = art.Substring(1, 20);
            FARBE = art.Substring(23, 10);
            QueryCommand(null, null);
            vwMaster.View.MoveCurrentToFirst();
            base.OnCARTChg(art);
        }
    }
}
